package com.nexmo.hangman.service.impl;

import com.nexmo.hangman.dao.UserDao;
import com.nexmo.hangman.domain.Game;
import com.nexmo.hangman.domain.GameState;
import com.nexmo.hangman.domain.User;
import com.nexmo.hangman.service.GameProvider;
import com.nexmo.hangman.service.utils.WordGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GameProviderImpl implements GameProvider {

    private static final int DEFAULT_LIVES = 6;
    private final UserDao userDao;
    private final WordGenerator wordGenerator;

    private static final String[] WORD_LIST = {};

    @Autowired
    public GameProviderImpl(UserDao userDao, WordGenerator wordGenerator) {
        this.userDao = userDao;
        this.wordGenerator = wordGenerator;
    }


    @Override
    public Game generateGame(Long userId) {
        Game game = new Game();
        String word = wordGenerator.getWord();
        game.setWordToGuess(word);

        GameState gameState = new GameState();
        gameState.setLivesRemaining(DEFAULT_LIVES);
        gameState.setIntroduced("");

        game.setState(gameState);
        gameState.setGame(game);
        User user = userDao.findById(userId);
        game.setUser(user);

        return game;
    }
}
